﻿/*
Copyright © 2011 François Karman

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

See <license.txt> for the complete license of the software.
*/

using System;

namespace Simple.Storage
{
    /// <summary>
    /// Defines the concept of index on persisted class.
    /// </summary>
    /// <remarks>
    /// The implementations of this interface should be immutable to avoid any side effect.
    /// </remarks>
    public interface IIndexDefinition
    {
        /// <summary>
        /// Gets the name of the index.
        /// </summary>
        /// <remarks>
        /// This name should be unique for the associated <see cref="IIndexDefinition.Type"/>.
        /// </remarks>
        string Name { get; }

        /// <summary>
        /// Gets the type of the persisted instances.
        /// </summary>
        Type Type { get; }

        /// <summary>
        /// Gets the type of the associated indexed values.
        /// </summary>
        Type IndexType { get; }

        /// <summary>
        /// Retrieves the index of an object associated with this definition.
        /// </summary>
        /// <param name="value">A <see cref="IIndexDefinition.Type"/> instance.</param>
        /// <returns>
        /// The associated identifier  of <see cref="IIndexDefinition.IndexType"/> type.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="value"/> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// The <paramref name="value"/> is not an instance of <see cref="IIndexDefinition.Type"/>.
        /// </exception>
        object RetrieveIndexValue(object value);
    }
}
